home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Very Best of Atari Inside
/
The Very Best of Atari Inside 1.iso
/
mint
/
mntlib43
/
mntlib
/
dup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-14
|
1KB
|
69 lines
/* from Dale Schumacher's dLibs library */
/* these will have to be adjusted at some time ++jrb */
/* use these with caution, TOS 1.4 still has double re-direction bug! */
#include <stddef.h>
#include <fcntl.h>
#include <osbind.h>
#include <errno.h>
#include <mintbind.h>
#include <unistd.h>
#include "lib.h"
extern int __mint;
int
dup(handle)
int handle;
{
register int rv;
long flags;
if (__mint)
rv = (int)Fcntl(handle, (long)0, F_DUPFD);
else
rv = (int)Fdup(handle);
if (rv < (__SMALLEST_VALID_HANDLE)) {
errno = -rv;
rv = -1;
}
else
{
if (__OPEN_INDEX(rv) < __NHANDLES) {
__open_stat[__OPEN_INDEX(rv)] =
__open_stat[__OPEN_INDEX(handle)];
}
if (__mint) {
flags = (long)Fcntl(rv, (long)0, F_GETFD);
(void)Fcntl(rv, flags & ~FD_CLOEXEC, F_SETFD);
}
}
return(rv);
}
int
dup2(handle1, handle2)
int handle1, handle2;
{
int rv;
long flags;
if (handle1 == handle2)
return (handle2);
if ((rv = (int)Fforce(handle2, handle1)) < 0)
errno = -rv;
else {
if (__OPEN_INDEX(handle2) < __NHANDLES)
__open_stat[__OPEN_INDEX(handle2)] =
__open_stat[__OPEN_INDEX(handle1)];
if (__mint) {
flags = (long)Fcntl(handle2, (long)0, F_GETFD);
(void)Fcntl(handle2, flags & ~FD_CLOEXEC, F_SETFD);
}
}
return (rv < 0) ? -1 : handle2;
}